
log using "/Users/Amit/OneDrive - Center for Disease Dynamics, Economics & Policy/Ongoing projects/NFHS-5 Research shared/mortality v2.smcl", replace

use "/Users/Amit/OneDrive - Center for Disease Dynamics, Economics & Policy/Ongoing projects/NFHS-5 Research/Dataset/Generated/child_clean.dta", clear

****merge files***
gen matching=substr(caseid,1,12)
destring matching, replace
merge n:1 matching using "/Users/Amit/OneDrive - Center for Disease Dynamics, Economics & Policy/Ongoing projects/NFHS-5 Research shared/head_educ.dta", force
keep if _merge==3

***generate and label additional control variables***
label define head_edu 0 "no education" 1 "primary" 2 "secondary" 3 "higher"
label values head_edu head_edu
tab head_edu
replace head_edu=. if head_edu==8

replace child_birthweight=. if child_birthweight>=9981

**generate child z-scores
*by day
bysort child_agedays sex_child: egen mean_height=mean(child_height)
bysort child_agedays sex_child: egen sd_height=sd(child_height)
gen z_child_height=(child_height-mean_height)/sd_height
bysort child_agedays sex_child: egen mean_weight=mean(child_weight)
bysort child_agedays sex_child: egen sd_weight=sd(child_weight)
gen z_child_weight=(child_weight-mean_weight)/sd_weight


*by week
bysort child_ageweeks sex_child: egen mean_height2=mean(child_height)
bysort child_ageweeks sex_child: egen sd_height2=sd(child_height)
gen z_child_height2=(child_height-mean_height2)/sd_height2
bysort child_ageweeks sex_child: egen mean_weight2=mean(child_weight)
bysort child_ageweeks sex_child: egen sd_weight2=sd(child_weight)
gen z_child_weight2=(child_weight-mean_weight2)/sd_weight2

**wealth groups
gen rich=1 if wealth_index>=3 & wealth_index<=5
replace rich=0 if wealth_index>=1 & wealth_index<=2

**label variables
label variable child_agemonth "Child age (months)"
label variable respondent_height "Mother age"
label variable respondent_age "Mother age"

**gen mother id
egen districtD=group(district)
tostring mother_no  cluster districtD hh_id, replace

gen mother_id=districtD+cluster+hh_id+mother_no
destring mother_id, replace

**g hhid
g hh_id2=districtD+cluster+hh_id
 destring hh_id2, replace
  destring hh_id, replace
 replace hh_id=hh_id2
 



**generate dummy variables for matching
foreach vname of varlist  region place_residence religion_cat1 caste_cat hh_size head_age_cat head_edu head_sex marital_status_cat respondent_edu state  wealth_index sex_child  child_agemonth_cat   bord_cat place_delivery {
levelsof `vname', local(levs)
local dctname `:value label `vname''
foreach i of numlist `levs' {
  generate byte `vname'`i'=`vname'==`i'
  label variable `vname'`i' "`:label `dctname' `i''"
}
}


**state variables with UT combined into state4B for control3 - urban subsample does not have enough observations***
forvalues x=1/37{
	capture gen state`x'B=state`x'
}

gen state0B=1 if state37==1| state31==1 | state35==1 |state25 ==1| state11 ==1 | state4==1 | state15==1 | state34==1 | state30==1 | state13==1 | state14==1 | state17==1 | state16==1 | state2==1
drop state37B state31B state35B state25B state11B state4B state15B state34B state30B state13B state14B state17B state16B state2B
gen state4B=state0B

decode state,generate(stateB)

****generate treatment variables***

g t2_cdc=43913
gen age_t2=(t2_cdc-child_dob_cdc)

foreach x in 30 365 0{


/*control group born all years prior, child born before COVID control/after treatment, born 30 or 365 they are treated as missing
t2a  reflects if child was measured before or after the lockdown period*/

	gen t2A_`x'=1 if age_t2<0
replace t2A_`x'=0 if t2A_`x'==. & age_t2!=.
replace t2A_`x'=. if child_dob_cdc<t2_cdc & child_dob_cdc>t2_cdc-`x' & child_dob_cdc!=.

}

	replace t2A_0=1 if doi>t2_cdc
replace t2A_0=0 if doi<=t2_cdc


*define outcome variables
foreach x of varlist  stunting wasting underweight{
gen `x'1=1 if  `x'==1 | `x'==2
replace `x'1=0 if `x'>2 & `x'!=.
gen `x'2=1 if `x'==1
replace `x'2=0 if `x'>=2 & `x'!=.
}



*****************************
*********Analysis******
*******************

cd  "/Users/Amit/OneDrive - Center for Disease Dynamics, Economics & Policy/Ongoing projects/NFHS-5 Research shared/Output/Mortality/"

*************difference in control variables***********


matrix ttest=J(65,6,0)
local j=1
foreach x of varlist  region1-region6  place_residence2 religion_cat11-religion_cat15 caste_cat1-caste_cat4 hh_size2  head_sex2 marital_status_cat2 respondent_edu1-respondent_edu3     respondent_height respondent_age sex_child2 child_agemonth bord_cat1-bord_cat4 place_delivery2 wealth_index1-wealth_index5 head_edu0-head_edu3 head_age{
dis "`x'"
ttest `x', by(t2A_0)
mat ttest[`j',1]=r(mu_2)
mat ttest[`j',2]=r(sd_2)
mat ttest[`j',3]=r(mu_1)
mat ttest[`j',4]=r(sd_1)
mat ttest[`j',5]=ttest`y'[`j',1]- ttest`y'[`j',3]
mat ttest[`j',6]=r(p)
local j=`j'+1
}
mat colnames ttest="Intervention mean" " Intervention SD" "Control mean" "Control SD" "Difference" "P-value"
local rows 
foreach var of varlist region1-region6 place_residence2 religion_cat11-religion_cat15 caste_cat1-caste_cat4 hh_size2  head_sex2 marital_status_cat2 respondent_edu1-respondent_edu3     respondent_height respondent_age sex_child2 child_agemonth bord_cat1-bord_cat4 place_delivery2 wealth_index1-wealth_index5 head_edu0-head_edu3 head_age{
local this = strtoname("`: variable label `var''") 
local rows `rows' `this'
}
mat rownames ttest=`rows'

putexcel set descriptive.xlsx, replace
putexcel A1=matrix(ttest),  overwritefmt   names


*observations for ttest
eststo clear
eststo P1: reg t2A_0 region1-region6 place_residence2 religion_cat12-religion_cat15 caste_cat2-caste_cat4 hh_size2  head_sex2 marital_status_cat2 respondent_edu1-respondent_edu3     respondent_height respondent_age sex_child2 child_agemonth bord_cat2-bord_cat4 place_delivery2 wealth_index1-wealth_index5 head_edu0-head_edu3 head_age

esttab using table1_N.xls, unstack p noomitted    label varwidth(27) delimiter(;) modelwidth(7) wrap prefoot("") postfoot("")  legend style(fixed)  replace



*************matching analysis***********


matrix results=J(10, 5, 0)
mat colnames results= "ATT" "p-value" "LB" "UB" "Sample size"
mat rowname results="stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z" "stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z"

matrix results_test=J(24,4,0)
mat colnames results_test="Psuedo R2" "P>Chi2" "Mean bias" "Median bias"



local controls "state1-state37  place_residence2 wealth_index1-wealth_index5 religion_cat12-religion_cat15 caste_cat2-caste_cat4 hh_size2  head_sex2 head_age_cat1-head_age_cat4  marital_status_cat2 respondent_edu1-respondent_edu3   sex_child2  respondent_height respondent_age child_agemonth bord_cat2-bord_cat4 place_delivery2 head_edu0-head_edu3  "
local outcomes "30 365" 

local i=1
			
			
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

 psmatch2 t2A_0 `controls' , outcome(`x') neighbor(1) ai(1) common

mat results[`i',1]= r(att)
mat results[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results[`i',3]= r(att)-1.96*r(seatt)
mat results[`i',4]= r(att)+1.96*r(seatt)
mat results[`i',5]= e(N)

  pstest, both


mat results_test[`i'*2-1,1]=r(r2aft)
mat results_test[`i'*2-1,2]=r(chiprobaft) 
mat results_test[`i'*2-1,3]=r(meanbiasaft) 
mat results_test[`i'*2-1,4]=r(medbiasaft) 


mat results_test[`i'*2,1]=r(r2bef)
mat results_test[`i'*2,2]=r(chiprobbef) 
mat results_test[`i'*2,3]=r(meanbiasbef) 
mat results_test[`i'*2,4]=r(medbiasbef) 


local i=`i'+1
}

local i=6

	
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if interview_year<=2020, outcome(`x') neighbor(1) ai(1) common 
 

		mat results[`i',1]= r(att)
mat results[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results[`i',3]= r(att)-1.96*r(seatt)
mat results[`i',4]= r(att)+1.96*r(seatt)
mat results[`i',5]= e(N)

  pstest, both


mat results_test[`i'*2-1,1]=r(r2aft)
mat results_test[`i'*2-1,2]=r(chiprobaft) 
mat results_test[`i'*2-1,3]=r(meanbiasaft) 
mat results_test[`i'*2-1,4]=r(medbiasaft) 


mat results_test[`i'*2,1]=r(r2bef)
mat results_test[`i'*2,2]=r(chiprobbef) 
mat results_test[`i'*2,3]=r(meanbiasbef) 
mat results_test[`i'*2,4]=r(medbiasbef) 


local i=`i'+1
}


putexcel set psm_results.xlsx, replace
putexcel A1=matrix(results),  overwritefmt   names

putexcel set psm_results_test.xlsx, replace
putexcel A1=matrix(results_test),  overwritefmt   names

**********************************
*************************rich subsmaple 



matrix results_rich=J(10, 5, 0)
mat colnames results_rich= "ATT" "p-value" "LB" "UB" "Sample size"
mat rowname results_rich="stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z" "stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z"

matrix results_test_rich=J(24,4,0)
mat colnames results_test_rich="Psuedo R2" "P>Chi2" "Mean bias" "Median bias"

		
local i=1
			
			
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if rich==1, outcome(`x') neighbor(1) ai(1) common

mat results_rich[`i',1]= r(att)
mat results_rich[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_rich[`i',3]= r(att)-1.96*r(seatt)
mat results_rich[`i',4]= r(att)+1.96*r(seatt)
mat results_rich[`i',5]= e(N)

  pstest, both



mat results_test_rich[`i'*2-1,1]=r(r2aft)
mat results_test_rich[`i'*2-1,2]=r(chiprobaft) 
mat results_test_rich[`i'*2-1,3]=r(meanbiasaft) 
mat results_test_rich[`i'*2-1,4]=r(medbiasaft) 


mat results_test_rich[`i'*2,1]=r(r2bef)
mat results_test_rich[`i'*2,2]=r(chiprobbef) 
mat results_test_rich[`i'*2,3]=r(meanbiasbef) 
mat results_test_rich[`i'*2,4]=r(medbiasbef) 
local i=`i'+1
}

local i=6

	
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if interview_year<=2020 & rich==1, outcome(`x') neighbor(1) ai(1) common

mat results_rich[`i',1]= r(att)
mat results_rich[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_rich[`i',3]= r(att)-1.96*r(seatt)
mat results_rich[`i',4]= r(att)+1.96*r(seatt)
mat results_rich[`i',5]= e(N)

  pstest, both



mat results_test_rich[`i'*2-1,1]=r(r2aft)
mat results_test_rich[`i'*2-1,2]=r(chiprobaft) 
mat results_test_rich[`i'*2-1,3]=r(meanbiasaft) 
mat results_test_rich[`i'*2-1,4]=r(medbiasaft) 


mat results_test_rich[`i'*2,1]=r(r2bef)
mat results_test_rich[`i'*2,2]=r(chiprobbef) 
mat results_test_rich[`i'*2,3]=r(meanbiasbef) 
mat results_test_rich[`i'*2,4]=r(medbiasbef) 
local i=`i'+1
}


putexcel set psm_results_rich.xlsx, replace
putexcel A1=matrix(results_rich),  overwritefmt   names


putexcel set psm_results_test_rich.xlsx, replace
putexcel A1=matrix(results_test_rich),  overwritefmt   names


********************poor 



matrix results_poor=J(10, 5, 0)
mat colnames results_poor= "ATT" "p-value" "LB" "UB" "Sample size"
mat rowname results_poor="stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z" "stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z"


matrix results_test_poor=J(24,4,0)
mat colnames results_test_poor="Psuedo R2" "P>Chi2" "Mean bias" "Median bias"


	
			local i=1
			
			
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if rich==0, outcome(`x') neighbor(1) ai(1) common

mat results_poor[`i',1]= r(att)
mat results_poor[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_poor[`i',3]= r(att)-1.96*r(seatt)
mat results_poor[`i',4]= r(att)+1.96*r(seatt)
mat results_poor[`i',5]= e(N)

  pstest, both


mat results_test_poor[`i'*2-1,1]=r(r2aft)
mat results_test_poor[`i'*2-1,2]=r(chiprobaft) 
mat results_test_poor[`i'*2-1,3]=r(meanbiasaft) 
mat results_test_poor[`i'*2-1,4]=r(medbiasaft) 


mat results_test_poor[`i'*2,1]=r(r2bef)
mat results_test_poor[`i'*2,2]=r(chiprobbef) 
mat results_test_poor[`i'*2,3]=r(meanbiasbef) 
mat results_test_poor[`i'*2,4]=r(medbiasbef) 

local i=`i'+1
}

local i=6

	
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if interview_year<=2020 & rich==0, outcome(`x') neighbor(1) ai(1) common

mat results_poor[`i',1]= r(att)
mat results_poor[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_poor[`i',3]= r(att)-1.96*r(seatt)
mat results_poor[`i',4]= r(att)+1.96*r(seatt)
mat results_poor[`i',5]= e(N)

  pstest, both

mat results_test_poor[`i'*2-1,1]=r(r2aft)
mat results_test_poor[`i'*2-1,2]=r(chiprobaft) 
mat results_test_poor[`i'*2-1,3]=r(meanbiasaft) 
mat results_test_poor[`i'*2-1,4]=r(medbiasaft) 


mat results_test_poor[`i'*2,1]=r(r2bef)
mat results_test_poor[`i'*2,2]=r(chiprobbef) 
mat results_test_poor[`i'*2,3]=r(meanbiasbef) 
mat results_test_poor[`i'*2,4]=r(medbiasbef) 

local i=`i'+1
}


putexcel set psm_results_poor.xlsx, replace
putexcel A1=matrix(results_poor),  overwritefmt   names

putexcel set psm_results_test_poor.xlsx, replace
putexcel A1=matrix(results_test_poor),  overwritefmt   names



**********************rural



matrix results_rural=J(10, 5, 0)
mat colnames results_rural= "ATT" "p-value" "LB" "UB" "Sample size"
mat rowname results_rural="stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z" "stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z"
local i=1

matrix results_test_rural=J(24,4,0)

mat colnames results_test_rural="Psuedo R2" "P>Chi2" "Mean bias" "Median bias"


local outcomes "30 365" 
local i=1

	
local i=1
			
			
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if place_residence2==1, outcome(`x') neighbor(1) ai(1) common

mat results_rural[`i',1]= r(att)
mat results_rural[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_rural[`i',3]= r(att)-1.96*r(seatt)
mat results_rural[`i',4]= r(att)+1.96*r(seatt)
mat results_rural[`i',5]= e(N)

  pstest, both


mat results_test_rural[`i'*2-1,1]=r(r2aft)
mat results_test_rural[`i'*2-1,2]=r(chiprobaft) 
mat results_test_rural[`i'*2-1,3]=r(meanbiasaft) 
mat results_test_rural[`i'*2-1,4]=r(medbiasaft) 


mat results_test_rural[`i'*2,1]=r(r2bef)
mat results_test_rural[`i'*2,2]=r(chiprobbef) 
mat results_test_rural[`i'*2,3]=r(meanbiasbef) 
mat results_test_rural[`i'*2,4]=r(medbiasbef) 
 


local i=`i'+1
}



local i=6

	
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if interview_year<=2020 & place_residence2==1, outcome(`x') neighbor(1) ai(1) common

mat results_rural[`i',1]= r(att)
mat results_rural[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_rural[`i',3]= r(att)-1.96*r(seatt)
mat results_rural[`i',4]= r(att)+1.96*r(seatt)
mat results_rural[`i',5]= e(N)

  pstest, both


mat results_test_rural[`i'*2-1,1]=r(r2aft)
mat results_test_rural[`i'*2-1,2]=r(chiprobaft) 
mat results_test_rural[`i'*2-1,3]=r(meanbiasaft) 
mat results_test_rural[`i'*2-1,4]=r(medbiasaft) 


mat results_test_rural[`i'*2,1]=r(r2bef)
mat results_test_rural[`i'*2,2]=r(chiprobbef) 
mat results_test_rural[`i'*2,3]=r(meanbiasbef) 
mat results_test_rural[`i'*2,4]=r(medbiasbef) 



local i=`i'+1
}


putexcel set psm_results_rural.xlsx, replace
putexcel A1=matrix(results_rural),  overwritefmt   names


putexcel set psm_results_test_rural.xlsx, replace
putexcel A1=matrix(results_test_rural),  overwritefmt   names


**************************urban


matrix results_urban=J(10, 5, 0)
mat colnames results_urban= "ATT" "p-value" "LB" "UB" "Sample size"
mat rowname results_urban="stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z" "stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z"




matrix results_test_urban=J(24,4,0)
mat colnames results_test_urban="Psuedo R2" "P>Chi2" "Mean bias" "Median bias"





local i=1
			
			
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if place_residence2==0, outcome(`x') neighbor(1) ai(1) common

mat results_urban[`i',1]= r(att)
mat results_urban[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_urban[`i',3]= r(att)-1.96*r(seatt)
mat results_urban[`i',4]= r(att)+1.96*r(seatt)
mat results_urban[`i',5]= e(N)


  pstest, both


mat results_test_urban[`i'*2-1,1]=r(r2aft)
mat results_test_urban[`i'*2-1,2]=r(chiprobaft) 
mat results_test_urban[`i'*2-1,3]=r(meanbiasaft) 
mat results_test_urban[`i'*2-1,4]=r(medbiasaft) 


mat results_test_urban[`i'*2,1]=r(r2bef)
mat results_test_urban[`i'*2,2]=r(chiprobbef) 
mat results_test_urban[`i'*2,3]=r(meanbiasbef) 
mat results_test_urban[`i'*2,4]=r(medbiasbef) 

local i=`i'+1
}

local i=6

	
foreach x of varlist stunting1 wasting1{

dis "`x' psmatch"

  psmatch2 t2A_0  `controls' if interview_year<=2020 & place_residence2==0, outcome(`x') neighbor(1) ai(1) common

mat results_urban[`i',1]= r(att)
mat results_urban[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_urban[`i',3]= r(att)-1.96*r(seatt)
mat results_urban[`i',4]= r(att)+1.96*r(seatt)
mat results_urban[`i',5]= e(N)


dis "`x'   pstest"

  pstest, both


mat results_test_urban[`i'*2-1,1]=r(r2aft)
mat results_test_urban[`i'*2-1,2]=r(chiprobaft) 
mat results_test_urban[`i'*2-1,3]=r(meanbiasaft) 
mat results_test_urban[`i'*2-1,4]=r(medbiasaft) 


mat results_test_urban[`i'*2,1]=r(r2bef)
mat results_test_urban[`i'*2,2]=r(chiprobbef) 
mat results_test_urban[`i'*2,3]=r(meanbiasbef) 
mat results_test_urban[`i'*2,4]=r(medbiasbef) 

local i=`i'+1
}



dis "underweight1 psmatch"

  psmatch2 t2A_0  `controls' if interview_year<=2020 & place_residence2==0, outcome(underweight1) neighbor(1) ai(1) common

mat results_urban[`i',1]= r(att)
mat results_urban[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_urban[`i',3]= r(att)-1.96*r(seatt)
mat results_urban[`i',4]= r(att)+1.96*r(seatt)
mat results_urban[`i',5]= e(N)


dis "underweight1   pstest"

  pstest, both


mat results_test_urban[`i'*2-1,1]=r(r2aft)
mat results_test_urban[`i'*2-1,2]=r(chiprobaft) 
mat results_test_urban[`i'*2-1,3]=r(meanbiasaft) 
mat results_test_urban[`i'*2-1,4]=r(medbiasaft) 


mat results_test_urban[`i'*2,1]=r(r2bef)
mat results_test_urban[`i'*2,2]=r(chiprobbef) 
mat results_test_urban[`i'*2,3]=r(meanbiasbef) 
mat results_test_urban[`i'*2,4]=r(medbiasbef) 

local i=`i'+1




foreach x of varlist height_for_age_z weight_for_height_z{

dis "`x' psmatch"

  psmatch2 t2A_0  `controls' if interview_year<=2020 & place_residence2==0, outcome(`x') neighbor(1) ai(1) common

mat results_urban[`i',1]= r(att)
mat results_urban[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_urban[`i',3]= r(att)-1.96*r(seatt)
mat results_urban[`i',4]= r(att)+1.96*r(seatt)
mat results_urban[`i',5]= e(N)


dis "`x'   pstest"

 pstest, both


mat results_test_urban[`i'*2-1,1]=r(r2aft)
mat results_test_urban[`i'*2-1,2]=r(chiprobaft) 
mat results_test_urban[`i'*2-1,3]=r(meanbiasaft) 
mat results_test_urban[`i'*2-1,4]=r(medbiasaft) 


mat results_test_urban[`i'*2,1]=r(r2bef)
mat results_test_urban[`i'*2,2]=r(chiprobbef) 
mat results_test_urban[`i'*2,3]=r(meanbiasbef) 
mat results_test_urban[`i'*2,4]=r(medbiasbef) 

local i=`i'+1
}


putexcel set psm_results_urban.xlsx, replace
putexcel A1=matrix(results_urban),  overwritefmt   names

putexcel set psm_results_test_urban.xlsx, replace
putexcel A1=matrix(results_test_urban),  overwritefmt   names





********************************male


matrix results_male=J(10, 5, 0)
mat colnames results_male= "ATT" "p-value" "LB" "UB" "Sample size"
mat rowname results_male="stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z" "stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z"

matrix results_male_test=J(24,4,0)
mat colnames results_male_test="Psuedo R2" "P>Chi2" "Mean bias" "Median bias"



local outcomes "30 365" 
local i=1


local i=1
			
			
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls'  if sex_child==1, outcome(`x') neighbor(1) ai(1) common

mat results_male[`i',1]= r(att)
mat results_male[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_male[`i',3]= r(att)-1.96*r(seatt)
mat results_male[`i',4]= r(att)+1.96*r(seatt)
mat results_male[`i',5]= e(N)

  pstest, both


mat results_male_test[`i'*2-1,1]=r(r2aft)
mat results_male_test[`i'*2-1,2]=r(chiprobaft) 
mat results_male_test[`i'*2-1,3]=r(meanbiasaft) 
mat results_male_test[`i'*2-1,4]=r(medbiasaft) 


mat results_male_test[`i'*2,1]=r(r2bef)
mat results_male_test[`i'*2,2]=r(chiprobbef) 
mat results_male_test[`i'*2,3]=r(meanbiasbef) 
mat results_male_test[`i'*2,4]=r(medbiasbef) 


local i=`i'+1
}

local i=6

	
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if interview_year<=2020 & sex_child==1, outcome(`x') neighbor(1) ai(1) common

mat results_male[`i',1]= r(att)
mat results_male[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_male[`i',3]= r(att)-1.96*r(seatt)
mat results_male[`i',4]= r(att)+1.96*r(seatt)
mat results_male[`i',5]= e(N)

  pstest, both


mat results_male_test[`i'*2-1,1]=r(r2aft)
mat results_male_test[`i'*2-1,2]=r(chiprobaft) 
mat results_male_test[`i'*2-1,3]=r(meanbiasaft) 
mat results_male_test[`i'*2-1,4]=r(medbiasaft) 


mat results_male_test[`i'*2,1]=r(r2bef)
mat results_male_test[`i'*2,2]=r(chiprobbef) 
mat results_male_test[`i'*2,3]=r(meanbiasbef) 
mat results_male_test[`i'*2,4]=r(medbiasbef) 


local i=`i'+1
}

putexcel set psm_results_male.xlsx, replace
putexcel A1=matrix(results_male),  overwritefmt   names

putexcel set psm_results_male_test.xlsx, replace
putexcel A1=matrix(results_male_test),  overwritefmt   names



************************female



matrix results_female=J(10, 5, 0)
mat colnames results_female= "ATT" "p-value" "LB" "UB" "Sample size"
mat rowname results_female="stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z" "stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z"

matrix results_female_test=J(24,4,0)
mat colnames results_female_test="Psuedo R2" "P>Chi2" "Mean bias" "Median bias"



local outcomes "30 365" 
local i=1


local i=1
			
			
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls'  if sex_child==2, outcome(`x') neighbor(1) ai(1) common

mat results_female[`i',1]= r(att)
mat results_female[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_female[`i',3]= r(att)-1.96*r(seatt)
mat results_female[`i',4]= r(att)+1.96*r(seatt)
mat results_female[`i',5]= e(N)

  pstest, both


mat results_female_test[`i'*2-1,1]=r(r2aft)
mat results_female_test[`i'*2-1,2]=r(chiprobaft) 
mat results_female_test[`i'*2-1,3]=r(meanbiasaft) 
mat results_female_test[`i'*2-1,4]=r(medbiasaft) 


mat results_female_test[`i'*2,1]=r(r2bef)
mat results_female_test[`i'*2,2]=r(chiprobbef) 
mat results_female_test[`i'*2,3]=r(meanbiasbef) 
mat results_female_test[`i'*2,4]=r(medbiasbef) 


local i=`i'+1
}

local i=6

	
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if interview_year<=2020 & sex_child==2, outcome(`x') neighbor(1) ai(1) common

mat results_female[`i',1]= r(att)
mat results_female[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_female[`i',3]= r(att)-1.96*r(seatt)
mat results_female[`i',4]= r(att)+1.96*r(seatt)
mat results_female[`i',5]= e(N)

  pstest, both


mat results_female_test[`i'*2-1,1]=r(r2aft)
mat results_female_test[`i'*2-1,2]=r(chiprobaft) 
mat results_female_test[`i'*2-1,3]=r(meanbiasaft) 
mat results_female_test[`i'*2-1,4]=r(medbiasaft) 


mat results_female_test[`i'*2,1]=r(r2bef)
mat results_female_test[`i'*2,2]=r(chiprobbef) 
mat results_female_test[`i'*2,3]=r(meanbiasbef) 
mat results_female_test[`i'*2,4]=r(medbiasbef) 


local i=`i'+1
}


putexcel set psm_results_female.xlsx, replace
putexcel A1=matrix(results_female),  overwritefmt   names

putexcel set psm_results_female_test.xlsx, replace
putexcel A1=matrix(results_female_test),  overwritefmt   names

****************************************************
******Robustness test with alternate controls*******
****************************************************

***merge nfhs4 data
drop _merge
merge m:1 stateB using  "/Users/Amit/OneDrive - Center for Disease Dynamics, Economics & Policy/Ongoing projects/child outcomes/health_nfhs4.dta"

eststo clear

gen stunting1_nfhs4=stunting_nfhs4 
gen  wasting1_nfhs4=wasting_nfhs4 
gen  underweight1_nfhs4=underweight_nfhs4
gen height_for_age_z_nfhs4=stunting1_nfhs4
gen weight_for_height_z_nfhs4=underweight1_nfhs4

***analysis

matrix results_alt=J(10, 5, 0)
mat colnames results_alt= "ATT" "p-value" "LB" "UB" "Sample size"
mat rowname results_alt="stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z" "stunting" "wasting" "underweight" "height_for_age_z" "weight_for_height_z"



local controls "stunting_nfhs4	wasting_nfhs4	underweight_nfhs4 state1-state37   place_residence2 wealth_index1-wealth_index5 religion_cat12-religion_cat15 caste_cat2-caste_cat4 hh_size2  head_sex2 head_age_cat1-head_age_cat4  marital_status_cat2 respondent_edu1-respondent_edu3   sex_child2  respondent_height respondent_age child_agemonth bord_cat2-bord_cat4 place_delivery2 head_edu0-head_edu3  "
local outcomes "30 365" 

local i=1


			
			
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

 psmatch2 t2A_0 `controls' , outcome(`x') neighbor(1) ai(1) common

mat results_alt[`i',1]= r(att)
mat results_alt[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_alt[`i',3]= r(att)-1.96*r(seatt)
mat results_alt[`i',4]= r(att)+1.96*r(seatt)
mat results_alt[`i',5]= e(N)


local i=`i'+1
}

local i=6

	
foreach x of varlist stunting1 wasting1 underweight1 height_for_age_z weight_for_height_z{

  psmatch2 t2A_0  `controls' if interview_year<=2020, outcome(`x') neighbor(1) ai(1) common 
 

		mat results_alt[`i',1]= r(att)
mat results_alt[`i',2]= 2*ttail(e(df_r),abs(r(att)/r(seatt))) 
mat results_alt[`i',3]= r(att)-1.96*r(seatt)
mat results_alt[`i',4]= r(att)+1.96*r(seatt)
mat results_alt[`i',5]= e(N)


local i=`i'+1
}


putexcel set psm_results_alt.xlsx, replace
putexcel A1=matrix(results_alt),  overwritefmt   names


log close

